import { createRouter, createWebHistory, useRouter } from 'vue-router'
import Layout from '@/layout/IndexView.vue'

// 为什么要用路由懒加载
// 有时我们并不需要所有路由的组件都加载。当匹配时再去加载对应的组件

// export const navigateToLogin = () => {
//   const router = useRouter() // 这个函数在组件中调用
//   router.push('/login')
// }

export { useRouter } from 'vue-router'

const routes = [
  {
    path: '/',
    component: Layout,
  },
  {
    path: '/login',
    component: () => import('@/view/login/indexView.vue'),
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
